package com.stephenone.zhdaily.comment.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.stephenone.zhdaily.R;
import com.stephenone.zhdaily.data.bean.Category;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by Administrator on 2018/1/31.
 */

public class CommentCategoryViewBinder extends ItemViewBinder<Category,CommentCategoryViewBinder.ViewHolder> {
    private ShortCommentCategoryClickListener mShortCommentCategoryClickListener;
    public CommentCategoryViewBinder(ShortCommentCategoryClickListener clickListener) {
        mShortCommentCategoryClickListener = clickListener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_comments_category_title, parent,
                false);
        return new CommentCategoryViewBinder.ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull Category item) {
        holder.mCount.setText(item.getCount() + "");
        if (item.isLongComment()) {
            holder.mTitle.setText("条长评");
        }else {
            holder.mTitle.setText("条短评");
        }
        holder.mItemView.setOnClickListener(v -> {
            if (mShortCommentCategoryClickListener != null && !item.isLongComment()) {
                mShortCommentCategoryClickListener.onShortCommentCategoryClick();
            }
        });
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView mCount;
        public TextView mTitle;
        public View mItemView;
        public ViewHolder(View itemView) {
            super(itemView);
            mCount = itemView.findViewById(R.id.tv_count);
            mTitle = itemView.findViewById(R.id.tv_title);
            mItemView = itemView;
        }
    }

    public interface ShortCommentCategoryClickListener{
        void onShortCommentCategoryClick();
    }
}
